<?php

/**
 * 微博抓取管理
 */

include_once($_SERVER["DOCUMENT_ROOT"] . "/core/inc.php");
include_once($_SERVER["DOCUMENT_ROOT"] . "/core/admin.inc.php");

include_once($_SERVER["DOCUMENT_ROOT"] . "/include/user/inc.php");
include_once($_SERVER["DOCUMENT_ROOT"] . "/include/mblog/inc.php");
include_once($_SERVER["DOCUMENT_ROOT"] . "/include/album/inc.php");
$g_cgival = array();
$g_pro = array();
$g_show = array();


function check_cgi_pro()
{
	global $g_cgival, $g_pro, $g_show;
		//页码
	cgi::get($g_cgival["p"], "p", 1);
	$g_cgival["p"] = intval($g_cgival["p"]);

	cgi::get($g_cgival["status"], "status", 1);
	cgi::get($g_cgival["show_index"], "show_index", "");
	cgi::get($g_cgival["title"], "title", "");
	
	$g_cgival["show_index"] = string::un_html($g_cgival["show_index"]);
	
	$g_cgival["title"] = string::un_html($g_cgival["title"]);
	cgi::get($g_cgival["is_tuijian"], "is_tuijian", 0);
	
	
	cgi::get($g_cgival["count_status"], "count_status", 0);
	cgi::get($g_cgival["album_id"], "album_id", 0);
	cgi::get($g_cgival["topic_id"], "topic_id", 0);
	
	
}

function get_data()
{
	global $g_cgival, $g_pro, $g_show,$config;
	$status = $g_cgival["status"];
	$title = $g_cgival["title"];
	$show_index = $g_cgival["show_index"];
	$album_id = $g_cgival["album_id"];
	$count_status = $g_cgival["count_status"];
	$is_tuijian = $g_cgival["is_tuijian"];
	$topic_id = $g_cgival["topic_id"];
	
	$g_cgival["pcount"] = 20;
	$db_album_info = new db_album_info();
	$db_user_info = new db_user_info();
	if($album_id)
	{
		$item = $db_album_info->admin_get_item($album_id);
		$list[] = $item;
		if($list)
		{
			$count = 1;
		}
		else
		{
			$count = 0;
		}
		
	}
	else
	{
		$count = $db_album_info->admin_get_count_by_search($status,$title,$show_index,$count_status,$is_tuijian,$topic_id);
		$list = $db_album_info->admin_get_list_by_search($g_cgival["status"],$g_cgival["p"],$g_cgival["pcount"],$title,$show_index,$count_status,$is_tuijian,$topic_id);
	
	}
	foreach($list as $key => $value)
	{
		$list[$key]["user_info"] = $db_user_info->get_user_info_item_by_uid($value["create_uid"]);
		$list[$key]["small_pic"] = str_replace("/large/","/thumbnail/",$value["pic"]);
		$list[$key]["pic2"] = str_replace("/bmiddle/","/square/",$list[$key]["pic2"]);
		$list[$key]["pic3"] = str_replace("/bmiddle/","/square/",$list[$key]["pic3"]);
		$list[$key]["pic4"] = str_replace("/bmiddle/","/square/",$list[$key]["pic4"]);
		
	}
	
	
	$g_show["count"] = $count;
	$g_show["list"] = $list;
	
	$max_page = page_bar::get_page_max($g_show["count"], $g_cgival["pcount"], $g_cgival["p"]);
	$page_bar_style = array(
			"curt"		=> $g_cgival["p"],
			"max"		=> $max_page,
			"key"		=> "p",
	);
	
	$g_show["page_bar"] = "<b>{$g_show["count"]}</b> 条记录&nbsp;&nbsp;第{$g_cgival["p"]}页&nbsp;共{$max_page}页&nbsp;" . page_bar::bar3($page_bar_style);
	
	$g_show["status"] = $g_cgival["status"];
	
}

$g_show["error"] = 0;
$g_show["errmsg"] = '';
try
{
	admin_check_login();
// 	admin_check_user_priv("foodv2/album_list.php");
	
	check_cgi_pro();
	get_data();
}
catch(Exception $e)
{
	$g_show["error"] = 1;
	$g_show["errmsg"] = $e->getMessage();
}

show_pro();
exit;


function show_pro()
{
	global $g_cgival, $g_pro, $g_show;
	if(isset($_GET['debug']))
		print_r($g_show);
	$smarty = p_get_smarty ();
	$smarty->assign ( 'g_show', $g_show );
	$smarty->display ( "mblog/album_list.html" );
}

